package com.beagle.njddapp.ui.presenter;

import com.beagle.njddapp.base.ApiService;
import com.beagle.njddapp.base.BasePresenter;
import com.beagle.njddapp.base.NjOwnerApiService;
import com.beagle.njddapp.base.RetrofitHttp;
import com.beagle.njddapp.bean.ZkBean;
import com.beagle.njddapp.bean.owner.OilOrderBean;
import com.beagle.njddapp.event.PayResultEvent;
import com.beagle.njddapp.net.BaseOilHttpResponse;
import com.beagle.njddapp.net.HttpResponseObserver;
import com.beagle.njddapp.net.RxSchedulers;
import com.beagle.njddapp.ui.view.NjOilOrderDetailView;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

import org.greenrobot.eventbus.EventBus;

import okhttp3.RequestBody;


public class NjOilOrderDetailPresenter extends BasePresenter<NjOilOrderDetailView> {
    private NjOwnerApiService apiService;

    public NjOilOrderDetailPresenter() {
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        //获取接口对象
        apiService = retrofit.create(NjOwnerApiService.class);

    }

    public void getOrderDetail(long orderId) {

        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"), "{}");

        apiService.oilOrderDeyail(orderId+"",body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpResponse<OilOrderBean>>() {
            @Override
            public void success(BaseOilHttpResponse<OilOrderBean> oilOrderBeanBaseOilHttpResponse) {
                if (oilOrderBeanBaseOilHttpResponse!=null){
                    getView().showOrder(oilOrderBeanBaseOilHttpResponse.result);
                }else {
                    getView().onError("");

                }
            }

            @Override
            public void error(int code, String message) {
                getView().onError(message);
            }
        });
    }

    public void getOrderInfo(long orderId ){
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        ApiService apiService = retrofit.create(ApiService.class);
        apiService.paymentInfo(orderId+"").compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpResponse<ZkBean>>() {
            @Override
            public void success(BaseOilHttpResponse<ZkBean> oilHttpResponse) {

                LogUtils.d("success");
                if (oilHttpResponse!=null&&oilHttpResponse.result!=null){
                    getView().showZkInfo(oilHttpResponse.result);
                }else {

                }
            }

            @Override
            public void error(int code, String message) {

            }
        });
    }
}